package com.arvinclub.model.entity;

import com.arvinclub.model.util.ToolsUtil;

import java.util.Date;
import java.util.List;

/**
 * 博客实体类
 */
public class Blog {
    /**
     * 用于数据库映射
     */
    private int id;
    private String content;//博客内容
    private Date date;//时间，面向数据库
    private User user;//此博客发布者
    private int status;//状态 1显示 0不显示
    private String filenames;//图片文件名，面向数据库
    private List<Comment> commentList;

    /**
     * 用于前端显示
     */
    private String time;//时间，面向前端
    private String[] filenameList;//图片文件名，面向前端

    private int commentCount;
    public void setFilenames(String filenames) {
        this.filenames = filenames;
        if (filenames != null)
            filenameList = filenames.split(" \n ");
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String[] getFilenameList() {
        return filenameList;
    }

    public String getTime() {
        if (time == null && date != null)
            time = ToolsUtil.SIMPLE_DATE_FORMAT.format(date);
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getFilenames() {
        return filenames;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getDate() {
        return date;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Comment> getCommentList() {
        return commentList;
    }

    public void setCommentList(List<Comment> commentList) {
        this.commentList = commentList;
    }

    public int getCommentCount() {
        return commentList.size();
    }

    @Override
    public String toString() {
        return id + ":" + content + ":" + ToolsUtil.SIMPLE_DATE_FORMAT.format(date) + "{" + user + "}";
    }


}
